package com.guaoran.other.observer.subject;

import com.guaoran.other.observer.core.Event;

import java.lang.reflect.Method;

public class ObserverTest {
    public static void main(String[] args) {
        try{
            //观察者
            Observer observer = new Observer();
            //通过反射获得方法
            Method advice = Observer.class.getMethod("advice", new Class<?>[]{Event.class});

            //注册四个事件进行监听
            Subject subject = new Subject();
            subject.addListener(SubjectEventType.ON_ADD,observer,advice);
            subject.addListener(SubjectEventType.ON_EDIT,observer,advice);
            subject.addListener(SubjectEventType.ON_REMOVE,observer,advice);
            subject.addListener(SubjectEventType.ON_QUERY,observer,advice);

            //进行添加动作
            subject.add();
            //进行删除动作
            subject.remove();

        }catch (Exception e){
            e.printStackTrace();
        }

    }

}
